package com.jdcjk.view;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jdcjk.R;

/**
 * Created by Administrator on 2016/12/23 0023.
 */

public class LoadingDialog extends ProgressDialog {
    private Context context;
    private View mView;
    public TextView mTextView;

    public LoadingDialog(Context context) {
        super(context);
        this.context = context;
    }

    public LoadingDialog(Context context, int id) {
        super(context, id);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.dialog_loading, null);
//        this.setContentView(mView);//错误写法，必须要先show（）再setContentView（），所以要重写show方法
        mTextView = (TextView) mView.findViewById(R.id.text_progressbar);
        this.setCanceledOnTouchOutside(false);//设置触摸外部界面不会使dialog消失
    }

    @Override
    public void show() {
//        this.show();错误写法，会不断调用导致stackoverflow
        super.show();
        this.setContentView(mView);
    }

    public void setTextView(String text) {
        mTextView.setText(text);
    }

    public void setTextView(int resId) {
        mTextView.setText(resId);
    }
}
